package com.micro.aop.interceptor;

import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Arrays;

public class LoggerMethodInterceptor implements MethodInterceptor {

    private static final Logger logger = LoggerFactory.getLogger(LoggerMethodInterceptor.class);

    @Override
    public Object invoke(MethodInvocation invocation) throws Throwable {
        Object result;
        try {
            result = invocation.proceed();
        } finally {
            logger.info("targetClass:{},method:{}, args:{}",
                    invocation.getThis().getClass().getName(),
                    invocation.getMethod().getName(),
                    Arrays.toString(invocation.getArguments()));
        }
        return result;
    }
}

